package com.moo2u2.android.oaktononthego.timesheet;

import android.content.Context;
import android.database.Cursor;
import android.graphics.Typeface;
import android.view.View;
import android.view.ViewGroup;
import android.widget.SimpleCursorAdapter;
import android.widget.TextView;

import com.moo2u2.android.oaktononthego.R;

public class TimesheetAdapter extends SimpleCursorAdapter {

    private boolean enabled;

    private static final int DISABLED_TXT = 0xFFdedede;
    private static final int DISABLED_BG = 0xFF232323;
    private static final int BLACK = 0xFF000000;
    private static final int WHITE = 0xFFffffff;

    public TimesheetAdapter(Context context, int layout, Cursor c,
            String[] from, int[] to) {
        super(context, layout, c, from, to);
    }

    @Override
    public View getView(int pos, View convertView, ViewGroup parent) {
        convertView = super.getView(pos, convertView, parent);

        TextView hours = (TextView) convertView.findViewById(R.id.hours);
        hours.setText(hours.getText() + " hrs");
        TextView subtype = (TextView) convertView.findViewById(R.id.subtype);
        TextView type = (TextView) convertView.findViewById(R.id.type);

        if (this.isEnabled()) {
            type.setTextColor(WHITE);
            subtype.setTextColor(WHITE);
            hours.setTextColor(WHITE);
            convertView.setBackgroundColor(BLACK);

            hours.setTypeface(Typeface.DEFAULT, Typeface.NORMAL);
            subtype.setTypeface(Typeface.DEFAULT, Typeface.NORMAL);
            type.setTypeface(Typeface.DEFAULT, Typeface.NORMAL);
        } else {
            type.setTextColor(DISABLED_TXT);
            subtype.setTextColor(DISABLED_TXT);
            hours.setTextColor(DISABLED_TXT);
            convertView.setBackgroundColor(DISABLED_BG);

            hours.setTypeface(Typeface.DEFAULT, Typeface.ITALIC);
            subtype.setTypeface(Typeface.DEFAULT, Typeface.ITALIC);
            type.setTypeface(Typeface.DEFAULT, Typeface.ITALIC);
        }

        return convertView;
    }

    public boolean isEnabled() {
        return enabled;
    }

    public void setEnabled(boolean enabled) {
        this.enabled = enabled;
    }

}
